﻿package zhou.chs.p2_7;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
//implements AdapterView.OnItemSelectedListener  声明监听选项选择事件
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
    TextView tv;     //声明TextView控件，显示联锁开关状态
    Spinner bps;       //声明Spinner控件，选择波特率
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=(TextView)findViewById(R.id.idtv);
        bps=(Spinner)findViewById(R.id.idbps);
        bps.setOnItemSelectedListener(this);  //注册选项选择事件监听
    }
    @Override    //选项选择事件响应
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
        String[] strbps = getResources().getStringArray(R.array.bps);
        tv.setText("串口波特率：" + strbps[i] + "bps");  //显示所选波特率
    }
    @Override   //没选择选项事件响应
    public void onNothingSelected(AdapterView<?> adapterView) {
    }
}